<!--
 * @Author: your name
 * @Date: 2021-08-31 20:22:28
 * @LastEditTime: 2021-09-06 16:46:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \新建文件夹 (6)\broker\src\views\home\Home.vue
-->
<template>
<div class="home">
    <div class="home_page">
        <!-- 经纪人主页标题 -->
        <div class="broker_tit">
            <h2>宏烨经纪人</h2>
            <div class="tit_end">
                <van-icon name="weapp-nav"></van-icon>
                <van-icon name="replay"></van-icon>
            </div>
        </div>
        <div class="broker_info">
            <p class="info_avatar"><img :src="'http://47.111.14.227:7001'+useInfo.user.avatar" alt=""></p>
            <span class="info_name">{{useInfo.user.nickname}}</span>
        </div>
        <!-- 房屋选择 -->
        <div class="house_select">
            <van-grid :column-num="3" :border="false">
                <van-grid-item v-for="(value,i) in houseSelect.houseType" :key="i" :to="value.path" >
                    <h3 class="total">{{total}}</h3>
                   <span class="houseType">{{value.text}}</span>
                </van-grid-item>
            </van-grid>
        </div>
    </div>
     <!-- 经纪人功能页面 -->
     <div class="broker_type">
            <van-grid :column-num="3" :border="false">
                <van-grid-item v-for="(value,i) in BrokerType.selectType" :key="i" :to="value.path" >
                    <img :src="value.srcUrl" alt="">
                </van-grid-item>
            </van-grid>
        </div>
    
</div>
</template>

<script>
import { defineComponent, onMounted, reactive ,ref} from 'vue'
import messageImg from '../../images/message.jpg'
import buyImg from '../../images/buyHouse.jpg'
import rentImg from '../../images/rent.jpg'
import floorImg from '../../images/floor.jpg'
import liveImg from '../../images/live.jpg'
import groupImg from '../../images/group.jpg'
import ranksImg from '../../images/banks.jpg'
import recordImg from '../../images/record.jpg'

import {getHouseDatum} from '../../api/getDatum'
import {Toast} from 'vant'
import {useRoute} from 'vue-router'

export default defineComponent({
  setup(props,context) {

    const route = useRoute();
    let useInfo = reactive({
        user:JSON.parse(localStorage.getItem('info'))
    })

    //   动态属性
      const bor = ref('20px')
    //   获取数据总数
      const total = ref(0)
    //   房屋功能选择选项
      const houseSelect = reactive({
          houseType:[
              {
                  'text':'新房',
                  'path':'/newHouse'
              },
              {
                  'text':'二手房',
                  'path':'/secondRoom'
              },
              {
                  'text':'出租房',
                  'path':'/rentOut'
              }
          ]
      });
    //   经纪人功能选项
      const BrokerType = reactive({
          selectType:[
              {
                  'srcUrl':messageImg,
                  'path':'/message'
              },
              {
                  'srcUrl':buyImg,
                  'path':'/qiugou'
              },
              {
                  'srcUrl':rentImg,
                  'path':'/qiuzu'
              },
              {
                  'srcUrl':floorImg,
                  'path':'/floor'
              },
              {
                  'srcUrl':liveImg,
                  'path':'/live'
              },
              {
                  'srcUrl':groupImg,
                  'path':'/tuan'
              },
              {
                  'srcUrl':ranksImg,
                  'path':'/top'
              },
              {
                  'srcUrl':recordImg,
                  'path':'/standings/standings1'
              }
          ]
      })

      const gethouse = async () => {
          const data = await getHouseDatum()
          console.log(data,'data');

          if(!data.meta.status === 200){
            Toast.fail('获取数据失败');
          }
          Toast.success('获取数据成功');

          total.value = data.data.total;
      }

      gethouse()

      return {    
        bor,
        houseSelect,
        BrokerType,
        total,
        useInfo
      }
  },
})
</script>

<style lang='less' scoped>
.home{
    width: 100%;
    height: 100%;
    .home_page{
        background: linear-gradient(
            135deg,
            rgba(2, 114, 240, 1) 0%, 
            rgba(2, 114, 240, 1) 0%, 
            rgba(57, 165, 255, 1) 100%, 
            rgba(57, 165, 255, 1) 100%
        );
        width: 100%;
        height: 230px;
        .broker_tit{
            width: 100%;
            height: 60px;
            padding: 0 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            h2{
                font-size: 20px;
                color: #fff;
            }
            .tit_end{
                width: 96px;
                height: 30px;
                border: 1px solid #fff;
                padding: 0 12px;
                border-radius: 40px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                i{
                    color: #fff;
                    font-size: 20px;
                }
            }
        }
        .broker_info{
            width: 100%;
            height: 150px;
            text-align: center;
            position: relative;
            .info_avatar{
                width: 94px;
                height: 94px;
                border-radius: 50%;
                margin: 0 auto;
                img{
                    display: block;
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                    border: 2px solid #fff;
                }
            }
            .info_name{
                padding-top: 16px;
                margin-bottom: 16px;
                display: block;
                color: #fff;
                font-size: 15px;
            }
        }
        .house_select{
            left: 10px;
            right: 10px;
            height: 96px;
            border-radius: 10px;
            position: absolute;
            background: #fff;
            color: #333;
            top: 204px;
            border: 1px solid #e8e8e8;
            .van-grid{
                margin-top: 5px;
                height: 80px;
                .van-grid-item__content{
                    height: 100%;
                }
                .total{
                    color: #53abf8;
                    font-size: 24px;
                }
                .houseType{
                    display: block;
                    color: #9b9c9b;
                    font-size: 14px;
                    margin-top: 13px;
                }
            }
        }
        
    }
    .broker_type{
        margin-top: 100px;
        width: 100%;
        img{
            width: 40px;
            height: 68px;
        }
    }
    
}

</style>
